#include <iostream>
#include <vector>
#include <queue>
using namespace std;

bool v[55][55];
struct Node{
    int row;
    int col;
};

bool ok(int r, int c, int m, int n){
    if(r < 0 || r>=m || c<0 || c>=n) return 0;
    return 1;
}

int dr[4] = {-1,1,0,0};
int dc[4] = {0,0,-1,1};

int maxAreaOfIsland(vector<vector<int>>& grid) {
    int m = grid.size();
    int n = grid[0].size();
    int ans = 0;
    int cnt = 0;
    for(int i=0;i<m;++i){
        for(int j=0;j<n;++j){
            if(grid[i][j] == 0 || v[i][j] == 1) continue;
            v[i][j] = 1;
            cnt = 1;
            queue<Node> Q;
            Q.push(Node{i,j});
            while(!Q.empty()){
                int r = Q.front().row;
                int c = Q.front().col;
                Q.pop();
                for(int k=0;k<4;k++){
                    int fr = r + dr[k];
                    int fc = c + dc[k];
                    if(ok(fr, fc, m, n) && !v[fr][fc] && grid[fr][fc] == 1){
                        v[fr][fc]  = 1;
                        cnt++;
                        Q.push(Node{fr,fc});
                    }
                }
            }
            ans = max(ans, cnt);
        }
    }
    return ans;
}